package com.dalin.system;

/******************************************************************************
 * @Desc   : 
 * @Author : najianlin
 * @Date   : yyyy/MM/dd HH:mm:ss
 * @Version: 1.0
 */
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTasks {

    // 每5秒执行一次
    @Scheduled(fixedRate = 5000)
    public void fixedRateTask() {
        System.out.println("Fixed rate task executed at " + new java.util.Date());
        System.out.println("5 seconds later");
    }

    // 每次任务完成后等待5秒再执行下一次任务
    @Scheduled(fixedDelay = 5000)
    public void fixedDelayTask() {
        System.out.println("Fixed delay task executed at " + new java.util.Date());
    }

    // 首次执行前等待1秒，之后每5秒执行一次
    @Scheduled(fixedRate = 5000, initialDelay = 1000)
    public void initialDelayTask() {
        System.out.println("Initial delay task executed at " + new java.util.Date());
    }

    // 每天凌晨1点执行任务（上海时区）
    @Scheduled(cron = "0 0 1 * * ?", zone = "Asia/Shanghai")
    public void cronTask() {
        System.out.println("Cron task executed at " + new java.util.Date());
        System.out.println("1 day later...................");
    }
}